import request from "../lib/request";

// 高级搜索
export async function advancedSearch(data: {
  keyword?: string;
  tags?: string[];
  mimeTypes?: string[];
  minWidth?: number;
  maxWidth?: number;
  minHeight?: number;
  maxHeight?: number;
  minFileSize?: number;
  maxFileSize?: number;
  startDate?: string;
  endDate?: string;
  page?: number;
  size?: number;
  sortBy?: string;
  sortDir?: string;
}) {
  return request({
    url: "/search/advanced",
    method: "POST",
    data,
  });
}

// 多标签筛选
export async function searchByTags(params: {
  tags: string[];
  logic: string;
  page: number;
  size: number;
  sortBy: string;
  sortDir: string;
}) {
  return request({
    url: "/search/tags",
    method: "GET",
    params,
  });
}

// 获取热门标签
export async function getPopularSearchTags(limit: number) {
  return request({
    url: "/search/popular-tags",
    method: "GET",
    params: { limit },
  });
}

// 获取标签云
export async function getTagCloud(maxTags: number) {
  return request({
    url: "/search/tag-cloud",
    method: "GET",
    params: { maxTags },
  });
}

// 按分类获取标签
export async function getTagsByCategory() {
  return request({
    url: "/search/tags-by-category",
    method: "GET",
  });
}

// 搜索建议（自动完成）
export async function getSearchSuggestions(query: string, limit: number) {
  return request({
    url: "/search/suggestions",
    method: "GET",
    params: { query, limit },
  });
}

// 获取相关标签
export async function getRelatedTags(tagName: string, limit: number) {
  return request({
    url: "/search/related-tags",
    method: "GET",
    params: { tagName, limit },
  });
}

// 快速搜索（简化版）
export async function quickSearch(params: {
  keyword: string;
  tags?: string[];
  mimeTypes?: string[];
  page: number;
  size: number;
}) {
  return request({
    url: "/search/quick",
    method: "GET",
    params,
  });
}

// 按时间范围搜索
export async function searchByDateRange(params: {
  startDate: string;
  endDate: string;
  keyword?: string;
  tags?: string[];
  page: number;
  size: number;
}) {
  return request({
    url: "/search/date-range",
    method: "GET",
    params,
  });
}

// 按文件大小范围搜索
export async function searchByFileSizeRange(params: {
  minSize?: number;
  maxSize?: number;
  keyword?: string;
  tags?: string[];
  page: number;
  size: number;
}) {
  return request({
    url: "/search/file-size-range",
    method: "GET",
    params,
  });
}

// 智能关键词搜索
export async function intelligentSearch(params: {
  keyword: string;
  page: number;
  size: number;
  sortBy: string;
  sortDir: string;
}) {
  return request({
    url: "/search/intelligent",
    method: "GET",
    params,
  });
}

// 获取热门搜索词
export async function getHotKeywords(limit: number) {
  return request({
    url: "/search/hot-keywords",
    method: "GET",
    params: { limit },
  });
}

// 记录搜索历史
export async function recordSearchHistory(data: { key: string }) {
  return request({
    url: "/search/history",
    method: "POST",
    data,
  });
}

// 搜索统计信息
export async function getSearchStatistics() {
  return request({
    url: "/search/statistics",
    method: "GET",
  });
}

// 根据图片Ids批量查询图片
export async function batchGetImageUrls(data: string[]) {
  return request({
    url: "/search/batch-urls",
    method: "POST",
    data,
  });
}
